<template>
  <div class="login-container">
    <div class="login-bg" id="login-bg"></div>
    <div class="long-connect">
      <div class="long-connectL">
        <div class="conL-box">
          <div class="conL-box1">
            <div class="conLBox">
              <div class="conL-box1Title">智慧食堂员工订餐管理平台</div>
            </div>

          </div>
          <div class="conL-box2"><img src="../assets/image/bg1.png" alt=""></div>
        </div>
      </div>
      <div class="long-connectR">
        <div class="conR-box1">登录账号</div>
        <div class="conR-box2">
          <el-form :model="loginForm" :rules="loginRules" ref="loginForm" class="login-input">
            <el-form-item prop="username">
              <el-input v-model="loginForm.username" placeholder="账号" autofocus clearable>
                <svg-icon slot="prefix" class="el-input__icon" icon-class="user"/>
              </el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input v-model="loginForm.password" type="password" placeholder="密码" :minlength="6" :maxlength="20" clearable>
                <svg-icon slot="prefix" class="el-input__icon" icon-class="password"/>
              </el-input>
            </el-form-item>
<!--            <el-form-item prop="validcode">-->
<!--              <el-input v-model="loginForm.validcode" :placeholder="translateKey('validcode')" :maxlength="4" clearable>-->
<!--                <template slot="append">-->
<!--                  <img class="login-validcode-img" :src="validcodeImg" @click="changeValidcode">-->
<!--                </template>-->
<!--              </el-input>-->
<!--            </el-form-item>-->
            <el-form-item>
              <el-button type="primary" class="btnClass" :loading="loading" @click.native.prevent="handleLogin">
                <span v-if="!loading">登 录</span>
                <span v-else>登 录 中...</span>
              </el-button>
            </el-form-item>
          </el-form>
        </div>
        <div></div>
      </div>
    </div>
    <div class="footer">
        <a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">陕ICP备2021007330号-1</a>
    </div>
  </div>
</template>
<!--<template>-->
<!--  <div class="login">-->
<!--    <div class="login-con">-->
<!--      <div class="login_title">-->
<!--        <img src="@/assets/login/login_title.png" alt="" height="48px" />-->
<!--      </div>-->
<!--      <div class="center-box">-->
<!--        <div class="center-right">-->
<!--          <el-form-->
<!--            ref="loginForm"-->
<!--            :model="loginForm"-->
<!--            :rules="loginRules"-->
<!--            class="login-form"-->
<!--          >-->
<!--            <div class="center_title">-->
<!--              <img src="@/assets/login/center_title.png" alt="" />-->
<!--            </div>-->
<!--            <el-form-item prop="username">-->
<!--              <el-input-->
<!--                v-model="loginForm.username"-->
<!--                type="text"-->
<!--                auto-complete="off"-->
<!--                placeholder="账号"-->
<!--              >-->
<!--                <svg-icon-->
<!--                  slot="suffix"-->
<!--                  icon-class="user"-->
<!--                  class="el-input__icon input-icon"-->
<!--                />-->
<!--              </el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item prop="password">-->
<!--              <el-input-->
<!--                v-model="loginForm.password"-->
<!--                type="password"-->
<!--                auto-complete="off"-->
<!--                placeholder="密码"-->
<!--                @keyup.enter.native="handleLogin"-->
<!--              >-->
<!--                <svg-icon-->
<!--                  slot="suffix"-->
<!--                  icon-class="password"-->
<!--                  class="el-input__icon input-icon"-->
<!--                />-->
<!--              </el-input>-->
<!--            </el-form-item>-->

<!--            <el-checkbox-->
<!--              v-model="loginForm.rememberMe"-->
<!--              style="margin: 0px 0px 25px 0px"-->
<!--              >记住密码</el-checkbox-->
<!--            >-->
<!--            <el-form-item style="width: 100%">-->
<!--              <el-button-->
<!--                :loading="loading"-->
<!--                size="medium"-->
<!--                type="primary"-->
<!--                style="width: 100%; padding: 15px 20px"-->
<!--                @click.native.prevent="handleLogin"-->
<!--              >-->
<!--                <span v-if="!loading">登 录</span>-->
<!--                <span v-else>登 录 中...</span>-->
<!--              </el-button>-->
<!--            </el-form-item>-->
<!--          </el-form>-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
<!--    &lt;!&ndash;  底部  &ndash;&gt;-->
<!--    <div class="el-login-footer">-->
<!--      <span>Copyright © 2018-2019 hmp All Rights Reserved.</span>-->
<!--    </div>-->
<!--  </div>-->
<!--</template>-->

<script>
import { getCodeImg } from "@/api/login";
import particlesjsConfig from '@/assets/particlesjs-config.json'
import 'particles.js'
import Cookies from "js-cookie";
import { encrypt, decrypt } from "@/utils/jsencrypt";

export default {
  name: "Login",
  data() {
    return {
      codeUrl: "",
      cookiePassword: "",
      loginForm: {
        username: "admin",
        password: "123456",
        rememberMe: false,
        code: "",
        uuid: "",
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "用户名不能为空" },
        ],
        password: [
          { required: true, trigger: "blur", message: "密码不能为空" },
        ],
      },
      loading: false,
      redirect: undefined,
    };
  },
  watch: {
    $route: {
      handler: function (route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true,
    },
  },
  created() {
    //this.getCode();
    this.getCookie();
  },
    mounted(){
        this.loadParticles()
    },
  methods: {
    loadParticles() {
        window.particlesJS('login-bg', particlesjsConfig)
    },
    getCookie() {
      const username = Cookies.get("username");
      const password = Cookies.get("password");
      const rememberMe = Cookies.get("rememberMe");
      this.loginForm = {
        username: username === undefined ? this.loginForm.username : username,
        password:
          password === undefined ? this.loginForm.password : decrypt(password),
        rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
      };
    },
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          if (this.loginForm.rememberMe) {
            Cookies.set("username", this.loginForm.username, { expires: 30 });
            Cookies.set("password", encrypt(this.loginForm.password), {
              expires: 30,
            });
            Cookies.set("rememberMe", this.loginForm.rememberMe, {
              expires: 30,
            });
          } else {
            Cookies.remove("username");
            Cookies.remove("password");
            Cookies.remove("rememberMe");
          }
          this.$store
            .dispatch("Login", this.loginForm)
            .then(() => {
              this.$router.push({ path: this.redirect || "/" });
            })
            .catch(() => {
              this.loading = false;
              //this.getCode();
            });
        }
      });
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss">
.login-container {
    flex-direction: column;
    overflow: hidden;
    .footer {
        position: fixed;
        bottom: 25px;
        left: 0;
        right: 0;
        text-align: center;
        color: #fff;
    }
}
.login {
  justify-content: center;
  align-items: center;
  height: 100%;
  min-height: 1100px;
  background: url("../assets/image/yinchuan.png") 100% 100%;
  background-size: cover;
  position: relative;
}
.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}
.login-con {
  width: 85%;
  padding-top: 2%;
  margin: 0 auto;
  height: 70%;
}
.login_title {
  text-align: center;
  margin-bottom: 3%;
}
.center-box {
  width:100%;
  height: 100%;
  border-radius: 6px;
  padding-top: 1%;
  .center_title {
    margin-bottom: 20px;
  }
  .center-right {
    width: 33%;
    max-width: 500px;
    min-width: 400px;
    float: right;
    margin-top: 100px;
    padding: 50px 0;
    background-color: rgba(48, 56, 51, 0.8);
    border-radius: 20px;

    box-sizing: border-box;
    button {
      margin-top: 20px;
      background-color: #78be20;
      border-radius: 5px;
    }
  }
  .input-yan {
    max-lines: 5;
  }
}

.center_title {
  text-align: center;
  padding: 5% 0 6% 0;
}
.login-form {
  width: 80%;
  margin: 0 auto;
  box-sizing: border-box;
  .el-input {
    height: 40px;
    input {
      height: 40px;
      line-height: 40px;
    }
  }
  .input-icon {
    height: 40px;
    width: 14px;
    margin-right: 8px;
  }
  .el-form-item {
    margin-bottom: 6%;
  }
}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.code-par {
  position: relative;
}
.login-code {
  position: absolute;
  right: 15px;
  width: 100px;
  height: 26px;
  top: 4px;
  img {
    cursor: pointer;
    width: 100px;
  }
}
.el-login-footer {
  height: 40px;
  line-height: 40px;
  // position: fixed;
  position: absolute;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.login_title img{
  width: 788px;
  height:70px ;
}
.login-container {

  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background:url('../assets/image/bg.png');

  min-width: max-content;
  min-width: -moz-max-content;
  background-size: cover;
  min-height: 750px;
}
.login-bg{
  width: 100%;
  height: 100%;
  position: absolute;
  overflow: hidden;
  // background-size: 100% 100%;
}

.bg {
  position: absolute;
  z-index: -1;
  width: 100%;
  height: 100%;
}
.long-connect{
  width: 60%;
  z-index: 99;
  // background-image: url('../../../static/img/ba1.png');
  background-size: 100% 100%;
  min-width: 1300px;
  // min-width: 1571px;
  height: 700px;
  background-color: white;
  border-radius: 10px;
  // margin: 0 auto;
  // position: absolute;
  // left: 20%;
  // top: 20%;
  // margin-top: 200px;
}
.long-connectL{
  width: 45%;
  height: 100%;
  min-width: 750px;
  // background-color: yellowgreen;
  float: left;
  display: flex;
  justify-content: center;
  align-items: center;
  .conL-box{
    width: 80%;
    height: 80%;
    // background-color: aquamarine;
  }
}
.long-connectR{
  width: 42%;
  min-width: 400px;
  height: 100%;
  // background-color:aquamarine;
  float: left;
  .conR-box1{
    width: 70%;
    height: 3%;
    margin: 0 auto;
    margin-top: 60px;
    font-size: 30px;
    line-height:120px;
    padding-left: 10px;
    box-sizing: border-box;
    color: #0067F4;
    // font-weight: 700;
    letter-spacing: 3px;
    // float: left;
  }
  .conR-box2{
    width: 80%;
    height: 78%;
    margin: 0 auto;
    padding: 40px;
    margin-top: 30px;
    box-sizing: border-box;
    // background-color: blueviolet;
  }
}
.conL-box1{
  width: 100%;
  height: 20%;
  position: relative;
  .conLBox{

  }
  .conL-box1Img{
    width: 173px;
    height: 50px;
    float: left;
    img{
      width: 100%;
    }

  }
  .conL-box1Title{
    width:100%;
    height: 100%;
    font-size: 34px;
    line-height:55px;
    padding-left: 10px;
    box-sizing: border-box;
    color: #0067F4;
    font-weight: 700;
    letter-spacing: 3px;
    text-align: center;
  }

}
.conL-box2{
  width: 100%;
  height: 70%;
  img{
    width: 100%;
    height: 100%;
  }
}


.login-form {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 100px;
  padding: 20px 15px;
 /*** margin-left: -(($form_width+30px)/2);-->
  width: $form_width; ***/
  background-color: #fff;
/*** @include box-shadow(0 0 15px 2px #d8dce5)***/
}
.login-logo {
 width: 100%;
 height: 110px;
}
.login-logo-img {
 width: 300px;
 height: 100px;
 margin: 0 auto;
 display: block;
}
/deep/
.el-form-item--mini.el-form-item, .el-form-item--small.el-form-item{
 margin-bottom: 40px;
}
.login-input {
 margin-top: 40px;
 .el-button {
   width: 100%;
 }
 /deep/ .el-input-group__append {
   padding: 0;
   margin: 0;
   border: 0;
 }
 .login-validcode-img {
   width: 90px;
   height: 50px;
   display: block;
   cursor: pointer;
 }
}
/deep/
.el-input--small .el-input__inner{
 height: 50px !important;
}
/deep/
.el-input__prefix{
 top: 9px;
 left: 9px;
}

.btnClass{
 width: 70% !important;
 display: block;
 margin: 80px auto 0;
 height: 40px;
}
</style>
